const express = require('express')
const router = express.Router()
const db = require('../../db')

router.post('/', (req, res) => {
  const { wx_id, new_nickname } = req.query
  // console.log(req.query)

  const setData = 'update easy_chat.users set nickname = ? where wx_id = ?'
  db.query(setData, [new_nickname, wx_id], (err, result) => {
    if (err) res.errHandle(err)
    // console.log(result)

    res.send({
      code: 200,
      message: 'success',
      data: {
        wx_id,
        new_nickname,
        message: '设置成功'
      }
    })
  })
})

module.exports = router
